package com.icomvn.game.pikachu.config;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.widget.ImageButton;
import android.widget.ImageView;

public class ResizeImage {
	public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
		 int width, height;
		width = bm.getWidth();
		
		 
		height =bm.getHeight();
		
		
		 
		float scaleWidth = ((float) newWidth) / width;
		 
		float scaleHeight = ((float) newHeight) / height;
		 
		// create a matrix for the manipulation
		 
		Matrix matrix = new Matrix();
		 
		// resize the bit map
		 
		matrix.postScale(scaleWidth, scaleHeight);
		 
		// recreate the new Bitmap
		 
		Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
		 
		return resizedBitmap;
		 
		}
	public static void resizeImage(ImageView img, int Height, int Width, int imgRes){
		 Bitmap bitmap = BitmapFactory.decodeResource(img.getResources(), imgRes);
	        
	        // anh moi duoc resize sao cho to bang man hinh
	        Bitmap img_new = getResizedBitmap(bitmap, Height, Width);
	        
	        // set cho imageview la anh moi
	        img.setImageBitmap(img_new);
	}
	
	public static void resizeImageButton(ImageButton img, int Height, int Width, int imgRes){
		 Bitmap bitmap = BitmapFactory.decodeResource(img.getResources(), imgRes);
	        
	        // anh moi duoc resize sao cho to bang man hinh
	        Bitmap img_new = getResizedBitmap(bitmap, Height, Width);
	        
	        // set cho imageview la anh moi
	        img.setImageBitmap(img_new);
	}
}
